#include "command.hpp"

int main()
{
    Fifo fifo(Path);

    int rfd = open(Path,O_RDONLY);
    if(rfd<0)
    {
        cerr<<"open error: "<<errno<<",errstring: "<<strerror(errno)<<endl;
        return -1;
    }
    //如果打开rfd时wfd还没打开，此时open会阻塞直到打开wfd，open才会返回

    //打开文件了
    cout<<"open rfd success"<<endl;

    char outbuffer[1024];
    while(1)
    {
        ssize_t n = read(rfd,outbuffer,sizeof(outbuffer));
        if(n<0)
        {
            cerr<<"read error: "<<errno<<",errstring: "<<strerror(errno)<<endl;
            break;
        }
        else if(n==0)
        {
            cout<<"client quit,me too"<<endl;
            break;
        }
        else
        {
            outbuffer[n] = '\0';//把最后置'\0'
            cout<<"client say:"<<outbuffer<<endl;
        }
    }

    return 0;
}